package com.me.modules.report.controller;

import com.me.modules.common.controller.BaseController;
import com.me.modules.common.utils.JsonUtil;
import com.me.modules.common.utils.Utils;
import com.me.modules.report.service.ProbReportService;
import com.me.modules.sys.entity.CodeEntity;
import com.me.modules.sys.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.*;


/**
 * 事件报表
 *
 * @author lill
 * @email lill5270@163.com
 * @date 2019-01-16 17:20:30
 */
@Controller
@RequestMapping("/report/probreport")
public class ProbReportController extends BaseController{
	@Autowired
	private ProbReportService probReportService;
	@Autowired
	private CodeService codeService;


	/**
	 * 列表
	 */
	@RequestMapping("/ProbClosePie")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String ProbClosePie(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List<Object> list =probReportService.ProbClosePie(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/problem/ProbClosePie";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/ProbGaugeOverstock")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String ProbGaugeOverstock(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Map map =probReportService.ProbGaugeOverstock(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(map));
		return "report/problem/ProbGaugeOverstock";
	}


	/**
	 * 列表
	 */
	@RequestMapping("/ProbLineOrginMonth")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String ProbLineOrginMonth(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List list =new ArrayList();
		List<CodeEntity> codeList  =codeService.queryChildsByMark("pro_reason");
		list.add(codeList);
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new Date());
		}
		List listColumn = new ArrayList();
		for (CodeEntity code :codeList) {
			params.put("reason",code.getValue());
			List<Object> month =probReportService.ProbLineOrginMonth(params);
			listColumn.add(month);
		}
		list.add(listColumn);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/problem/ProbLineOrginMonth";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/ProbChainDayNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String ProbChainDayNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",Utils.parse(new  Date(),"yyyy-MM"));
		}
		List<Object> list =probReportService.ProbLineDayNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/problem/ProbChainDayNumber";
	}

//	/**
//	 * 列表
//	 */
//	@RequestMapping("/IncLineDayNumber")
////	@RequiresPermissions("srminfo:list")
////	@SysLog("查询变更列表")
//	public String IncLineDayNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
//		Date endDate= (Date) params.get("endDate");
//		if(endDate==null){
//			params.put("endDate",Utils.parse(new  Date(),"yyyy-MM"));
//		}
//		List<Object> list =incReportService.IncLineDayNumber(params);
//		model.addAttribute("params",params);
//		model.addAttribute("data",JsonUtil.getJsonByObj(list));
//		return "report/incident/IncLineDayNumber";
//	}


	/**
	 * 列表
	 */
	@RequestMapping("/ProbYoyDayNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String ProbYoyDayNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List list =new ArrayList();
		List codeList  =new ArrayList();
		List listColumn = new ArrayList();
		Date beginDate= (Date) params.get("beginDate");
		Date endDate= (Date) params.get("endDate");

		Map<String, Object> oldparams=new HashMap<String, Object>();
		if(beginDate==null){
			oldparams.put("endDate",Utils.parse(new  Date(),"yyyy-MM"));
			List<Object> newList =probReportService.ProbLineDayNumber(oldparams);
			codeList.add(Utils.parse(new  Date(),"yyyy-MM"));
			listColumn.add(newList);
		}else{
			oldparams.put("endDate",Utils.parse(beginDate,"yyyy-MM"));
			codeList.add(Utils.parse(beginDate,"yyyy-MM"));
			List<Object> newList =probReportService.ProbLineDayNumber(oldparams);
			listColumn.add(newList);
		}

		if(endDate==null){
			oldparams.put("endDate", Utils.parse(new  Date(),"yyyy-MM"));
			List<Object> newList =probReportService.ProbLineDayNumber(oldparams);
			codeList.add(Utils.parse(new  Date(),"yyyy-MM"));
			listColumn.add(newList);
		}else{
//			oldparams.put("endDate",endDate);
			oldparams.put("endDate",Utils.parse(endDate,"yyyy-MM"));
			List<Object> newList =probReportService.ProbLineDayNumber(oldparams);
			codeList.add(Utils.parse(endDate,"yyyy-MM"));
			listColumn.add(newList);
		}
		list.add(codeList);
		list.add(listColumn);
//		List<Object> newList =incReportService.IncLineDayNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/problem/ProbYoyDayNumber";
	}









	/**
	 * 列表
	 */
	@RequestMapping("/ProbYoyMonthNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String ProbYoyMonthNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List list =new ArrayList();
		List codeList  =new ArrayList();
		List listColumn = new ArrayList();
		Date beginDate= (Date) params.get("beginDate");
		Date endDate= (Date) params.get("endDate");
		Map<String, Object> oldparams=new HashMap<String, Object>();
		if(beginDate==null){
			oldparams.put("endDate",new Date());
			codeList.add(Utils.formatDate(new Date()));
			List<Object> newList =probReportService.ProbLineMonthNumber(oldparams);
			listColumn.add(newList);
		}else{
			oldparams.put("endDate",beginDate);
			codeList.add(Utils.formatDate(beginDate));
			List<Object> newList =probReportService.ProbLineMonthNumber(oldparams);
			listColumn.add(newList);
		}

		if(endDate==null){
			oldparams.put("endDate",new Date());
			codeList.add(Utils.formatDate(new Date()));
			List<Object> newList =probReportService.ProbLineMonthNumber(oldparams);
			listColumn.add(newList);
		}else{
			oldparams.put("endDate",endDate);
			codeList.add(Utils.formatDate(endDate));
			List<Object> newList =probReportService.ProbLineMonthNumber(oldparams);
			listColumn.add(newList);
		}
		list.add(codeList);
		list.add(listColumn);
//		List<Object> list =incReportService.IncLineMonthNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/problem/ProbYoyMonthNumber";
	}



	/**
	 * 列表
	 */
	@RequestMapping("/ProbChainMonthNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String ProbChainMonthNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new  Date());
		}
		List<Object> list =probReportService.ProbLineMonthNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/problem/ProbChainMonthNumber";
	}




	/**
	 * 列表
	 */
	@RequestMapping("/ProbColumnOperatorNumTop10")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String ProbColumnOperatorNumTop10(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		params.put("fetchNumber",10);
		List<Object> list =probReportService.ProbColumnOperatorNumTop10(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/problem/ProbColumnOperatorNumTop10";
	}



}
